/**
 * 作者: hxl
 * 日期: 2025-03-15 16:04:18
 * 备注: 用户跨服限时充值任务表
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.server.game.commondata.act.ActRechargeTask;
import com.motu.monstercity.server.game.commondata.act.ActRechargeTaskType;
import com.motu.monstercity.server.game.logic.RankActUserData;
import com.motu.vertx.module.utility.model.EntityManager;
import com.motu.vertx.module.utility.toolset.TimeUtils;

public class UserCrossRechargeActTask extends UserCrossRechargeActTaskModel {
    public UserCrossRechargeActTask() {
        super();
    }

    public UserCrossRechargeActTask(long userId, long round, int configId, int taskType, long curP) {
        super();
        this.putUserId(userId);
        this.putRound(round);
        this.putConfigId(configId);
        this.putTaskType(taskType);
        this.putCurP(curP);
        putResetTime(TimeUtils.getCurTime());
        String actListKey = EntityManager.getFieldJoinString(userId, configId);
        this.putActListKey(actListKey);
        putRechargeTime(TimeUtils.getCurTime());
    }

    public void reset() {
        ActRechargeTaskType taskType = RankActUserData.getActRechargeTaskType(getTaskType());
        if (taskType == null) {
            return;
        }
        if (taskType.getType() == ActRechargeTaskType.RESET_TYPE_DAILY && !TimeUtils.isToday(getResetTime())) {
            putCurP(0);
            putResetTime(TimeUtils.getCurTime());
            update();
        }
    }

    public void checkRound(long round) {
        if (getRound() != round) {
            putCurP(0);
            putRound(round);
            update();
        }
    }

    public void addTaskValue(long value) {
        if (taskType == ActRechargeTask.TASK_TYPE_DAY_CHARGE) { // 累天充值
            super.addCurP(value);
            update();
//            if (!TimeUtils.isToday(getResetTime())) {
//                putResetTime(TimeUtils.getCurTime());
//            }
        } else {
            putCurP(getCurP() + value);
            update();
        }
    }
}
